package com.lei.yohuo001java;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lei.mvp_retrofitlibrary.http.bean.RegisterBean;
import com.lei.mvp_retrofitlibrary.mvp.view.BaseActivity;
import com.lei.yohuo001java.contract.ShopContract;
import com.lei.yohuo001java.model.ShopModel;
import com.lei.yohuo001java.presenter.ShopPresenter;

public class RegisterActivity extends BaseActivity<ShopPresenter> implements ShopContract.RegisterView {
    private EditText actRegEtName;
    private EditText actRegEtPwd;
    private Button actRegBtRegister;

    @Override
    public int bindlayout() {
        return R.layout.activity_register;
    }

    @Override
    public void initView() {
        actRegEtName = (EditText) findViewById(R.id.act_reg_et_name);
        actRegEtPwd = (EditText) findViewById(R.id.act_reg_et_pwd);
        actRegBtRegister = (Button) findViewById(R.id.act_reg_bt_register);
        mPrensenter = new ShopPresenter(new ShopModel(),this);
    }

    @Override
    public void initData() {
        actRegBtRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showToast("点击了");
                String name = actRegEtName.getText().toString().trim();
                String pwd = actRegEtPwd.getText().toString().trim();
                mPrensenter.initregister(name,pwd);
            }
        });
    }

    @Override
    public void showLayout() {

    }

    @Override
    public void hideLayout() {

    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, ""+msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void registerData(RegisterBean registerBean) {
        if (registerBean.getCode()==200){
            showToast("注册成功");
            finish();
        }else {
            showToast("注册失败"+registerBean.getMsg());
        }
    }
}
